var e = require("/model/awconfig.js"), a = require("/model/userModel.js"), o = require("/utils/util.js");

App({
    chaping(){
        let that = this
        that.globalData.interstitialAd = null
            if (wx.createInterstitialAd) {
                that.globalData.interstitialAd = wx.createInterstitialAd({
                  adUnitId: that.globalData.chaping
                })
                // let show = 1
                // wx.showLoading({
                //   title: '请稍等...',
                //   mask:true
                // })
                that.globalData.interstitialAd.onLoad(() => {
                    // if(show == 2){
                    //     return
                    // }
                    // show = 2
                    if (that.globalData.interstitialAd) {
                        
                        that.globalData.interstitialAd.show()
                        .then(()=>{
                            wx.hideLoading({
                              success: (res) => {},
                            })
                        })
                        .catch((err) => {
                            wx.hideLoading({
                                success: (res) => {},
                              })
                            console.error(err,'插屏广告show错误')
                        })
                    }
                })
                that.globalData.interstitialAd.onError((err) => {
                    console.log(err,'拉取广告错误')
                    wx.hideLoading({
                        success: (res) => {},
                      })
                })
                that.globalData.interstitialAd.onClose(() => {})
            }
        
    },
    onLaunch: function(e) {
        var a = this;
        console.log("App onLaunch"), wx.setStorageSync("show_global_tips", 1), wx.cloud ? wx.cloud.init({}) : console.error("请使用 2.2.3 或以上的基础库以使用云能力"), 
        o.setApp(a), a.getDeviceInfo();
        var n = o.getAuthTokenKey(), t = wx.getStorageSync(n);
        console.log(t), null != t && null != t || wx.setStorageSync(n, "");
        var i = e.scene;
        console.log("scene:" + i), wx.reportAnalytics("launch", {
            scene: i.toString()
        }), 1007 != i && 1008 != i || wx.setStorageSync("isByShare", 1), wx.setStorageSync("HadShowAlertAD", 0), 
        wx.setStorageSync("App", a.globalData.appName);
        var d = wx.getStorageSync(n);
        0 == o.hasToken() ? (console.log("authToken：" + d), a.login()) : wx.checkSession({
            success: function() {},
            fail: function() {
                a.login();
            }
        });
    },
    onShow: function(a) {
        console.log("App onShow");
        var n = this;
        wx.setStorageSync("App", n.globalData.appName), e.rootConfig(function(e) {
            o.globalTips(), e && e.hasOwnProperty("config_r_now") && 1 == e.config_r_now && n.loadConfig();
        }), n.loadConfig();
    },
    loadConfig: function() {
        var a = this;
        e.loadConfig(function(e) {
            console.log("data:" + e), e && e.hasOwnProperty("config_flag") && (wx.setStorageSync("appConfig", e), 
            a.awconfigSuccessCallback(), null != e.alwaysLogin && 1 == e.alwaysLogin && a.login());
        }, function(e) {}), a.awconfigSuccessCallback();
    },
    awconfigSuccessCallback: function() {
        var e = wx.getStorageSync("appConfig");
        null != e.openAuthToken && (this.globalData.openAuthToken = e.openAuthToken), null != e.syncRewardExpired && 1 == e.syncRewardExpired && o.syncRewardExpiredTime(), 
        this.globalData.openAuthToken;
    },
    login: function() {
        console.log("登录");
        var e = this;
        wx.login({
            success: function(n) {
                if (console.log(n.code), n.code) {
                    var t = {
                        code: n.code,
                        app: e.globalData.appName
                    };
                    console.log(t), a.login(t, function(e) {
                        console.log(e), 0 == e.status && wx.setStorageSync(o.getAuthTokenKey(), e.data.authToken);
                    }, function(e) {});
                } else console.log("登录失败！" + n.errMsg);
            }
        });
    },
    getDeviceInfo: function() {
        var e = this;
        wx.getSystemInfo({
            success: function(a) {
                e.globalData.systemInfo = a, "devtools" == a.platform || "ios" == a.platform || a.platform;
            }
        });
    },
    globalData: {
        appVersion: "1.2.5.3",
        host: "https://p.zexp.net/",
        loginHost: "https://p.zexp.net/",
        dHost: "https://db.zexp.net/",
        parsePath: "v3/pksmini",
        configPath: "https://ap.zexp.net/wxMiniConfig",
        authTokenKey: "AuthToken",
        showGongZhongHaoBottom: 1,
        adKeyHome: "adunit-0817cd0cd074357a",
        adKeyDYDownload: "adunit-02c402dce5480676",
        adKeyDYVideoInfo: "adunit-36f03503af57d6ca",
        adKeyDYMusic: "adunit-a87b26ce27c7089b",
        adKeyUserInifo: "adunit-e0ab18210d62f9eb",
        adKeyKSDownload: "adunit-f3300bbfcfcf2963",
        adKeyHSDownload: "adunit-63d2b2840677b0ae",
        adKeyAlert: "adunit-d0a3f76389353645",
        adKeyMore: "adunit-429ea058f26b07cb",
        adKeyImagesDetail: "adunit-6d9727848d7db6ca",
        adKeyImagesDetail2: "adunit-2b01bdfdf1da8cd2",
        adRewardedVideo1: "adunit-8bf85caf45ad534c",
        adRewardedVideo2: "adunit-0f4302ddfe8dd381",
        adInterstitial1: "adunit-4c81e801ae576f12",
        adInterstitialDYD: "adunit-4c81e801ae576f12",
        adInterstitialHome: "adunit-6e70abc67bf810b5",
        adInterstitialKSD: "adunit-4c81e801ae576f12",
        adVideoBanner1: "adunit-36f278333b076190",
        adVideoBanner2: "adunit-2797f07b59c178a7",
        adVideoBanner3: "adunit-f43868ae4b4863a8",
        ad_mode_banner_1: "adunit-ad9f417e98a5a1b0",
        ad_mode_banner_2: "adunit-29ac05cde42f06fe",
        ad_mode_banner_3: "adunit-67622efd76fd8c28",
        ad_mode_hover1: "adunit-09e63ee3b99eebff",
        ad_mode_hover2: "adunit-337d14817d574ebc",
        appName: "M_ShuiYin",
        appDisplayName: "西果工具",
        systemInfo: {},
        openAuthToken: 0,
        userInfo: null,
        interstitialAd: null,
        chaping:'adunit-7bc6314b59863722',
        jili:'adunit-ce63d91002f85834',
        videoId:'adunit-392063bb5ac25d30'
    }
});